//
//  DataInforVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/1/28.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "DataInforVC.h"
#import "dataTopCell.h"
#import "dataBottomCell.h"

@interface DataInforVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *table;

@end

@implementation DataInforVC{
    RequestServices *service;
    NSDictionary *valueDic;//获取到的字典值
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"资料详情";
    [self.backKuang setHidden:YES];
    [self showBackCenterKuang:[UIImage imageNamed:@"back_center1"]];
    service = [[RequestServices alloc]initWithDelegate:self];
    service.view = self.view;
    [service getClassData:self.courseId tag:8000];
}

-(void)showContent{
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.table registerNib:[UINib nibWithNibName:@"dataTopCell" bundle:nil] forCellReuseIdentifier:@"dataTopCell"];
    [self.table registerNib:[UINib nibWithNibName:@"dataBottomCell" bundle:nil] forCellReuseIdentifier:@"dataBottomCell"];
    self.table.tableFooterView = [UIView new];
}

#pragma mark - requestDelegate
-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    [self HideLoading];
    if (tag == 8000){
        [self showContent];
        valueDic = [NSDictionary dictionaryWithDictionary:obj];
    }
    [self.table reloadData];
}

-(void)getError:(NSError *)error tag:(long long)tag{
    [self HideLoading];
    [self ShowNewMsg:error.domain];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return SCREEN_H*0.3;
    }else{
        return SCREEN_H*0.8;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        dataTopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dataTopCell" forIndexPath:indexPath];
        cell.dataName_lab.text = [NSString stringWithFormat:@"资料名称:%@",valueDic[@"referenceName"]];
        cell.author_lab.text = [NSString stringWithFormat:@"作者 :%@",valueDic[@"referenceAuthor"]];
        cell.upLoadTime_lab.text = [NSString stringWithFormat:@"上传时间:%@",valueDic[@"referenceTime"]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        dataBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dataBottomCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([valueDic[@"referenceUrl"] containsString :@".jpg"] ) {
            UIImageView *img = [[UIImageView alloc]initWithFrame:cell.contentView.bounds];
            img.image = DefaultIcon;
            [cell.contentView addSubview:img];
        }
        return cell;
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
